/**
 * @Author: oldTea
 * @CreateTime: 2024-11-29
 * @Description:
 * @Version: 1.0
 */
package com.ambition.demo.juc;

import lombok.extern.slf4j.Slf4j;

/**
 *@Author: oldTea
 *@CreateTime: 2024-11-29
 *@Description: volatile可线程
 *@Version: 1.0
 */
@Slf4j
public class VolatileTest {

    private  static volatile boolean b = false;
    public static void main(String[] args) {

        new Thread(() -> {
            while (!b) {
            }
            System.out.println("线程A执行完毕");
        },"A线程").start();

        try {
            Thread.sleep(2000);
            System.out.println("主线程修改b为true");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        b = true;

    }
}


